/*
 * Copyright (c) dabing.io
 * All rights reserved.
 * ScheduleDmsTask.java
 */

package com.ueboot.weishop.admin.batch.schedule;

import com.ueboot.weishop.admin.batch.JobRunUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 描述: 定时任务 代金券下发DMS
 *
 * @author Yvan
 * @since 1.0
 */
@Component
@Configurable
@EnableScheduling
public class ScheduleDmsTask {
	private static final Logger logger = LoggerFactory.getLogger(ScheduleDmsTask.class);

	private final JobLauncher jobLauncher;

	private final JobRepository jobRepository;

	private final Job jobSendCouponDms;

	@Autowired
	public ScheduleDmsTask(JobLauncher jobLauncher, JobRepository jobRepository, Job jobSendCouponDms) {
		this.jobLauncher = jobLauncher;
		this.jobRepository = jobRepository;
		this.jobSendCouponDms = jobSendCouponDms;
	}

	//代金券下发DMS
	@Scheduled(cron = "0 */2 * * * ?")
//	@Scheduled(cron = "1 14 0 * * ?")
	public void executeSendCouponDms() {
		logger.info("创建每天需要执行结算任务的数据  开始......");
		JobParameters jobParameters = new JobParametersBuilder().addDate("reset",new Date()).toJobParameters();
		JobRunUtil.runJob(jobSendCouponDms, jobParameters, jobRepository, jobLauncher);
		logger.info("创建每天需要执行结算任务的数据  结束......");
	}
}